package com.wangzhen.bio.original;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;

public class BIOTest {

    public static void main(String[] args) throws IOException {
        ServerSocket ss = new ServerSocket(9999);
        while (true) {
            Socket socket = ss.accept();
            doRequest(socket);
        }
    }

    private static void doRequest(Socket socket) {
        try {
            OutputStream outputStream = socket.getOutputStream();
            PrintWriter writer = new PrintWriter(outputStream);
            String str = "hello world";
            writer.println("HTTP/1.1 200 OK");
            writer.println("Content-Type:text/html;charset=UTF-8");
            writer.println("Content-Length:"+ str.getBytes().length);
            writer.println();
            writer.println(str);
            writer.close();
            socket.close();
        } catch (IOException e) {
            System.err.println("do request error!");
        }
    }
}
